﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FraudMitigator
{
    static class InputValidator
    {
        // Use [type] to determine which check to run, then step through [data] to ensure it meets requirements.
        public static bool validateText(string type, string data)
        {
            if (data.Length == 0){ return false; }

            switch (type)
            {
                case "name":

                    for (int i = 0; i < data.Length; i++)
                    {
                        if (!((data[i] >= 'A' && data[i] <= 'Z') || (data[i] >= 'a' && data[i] <= 'z') || data[i] == '\'' || data[i] == '.'))
                            return false;
                    }
                    return true;

                case "address":

                    for (int i = 0; i < data.Length; i++)
                    {
                        if (!((data[i] >= 'A' && data[i] <= 'Z') || (data[i] >= 'a' && data[i] <= 'z') || (data[i] >= '0' && data[i] <= '9') 
                            || data[i] == '\'' || data[i] == '.' || data[i] == ' ' || data[i] == '-'))
                            return false;
                    }
                    return true;

                case "zip":

                    if (!(data.Length == 5 || data.Length == 9)) { return false; }
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (!(data[i] >= '0' && data[i] <= '9'))
                            return false;
                    }
                    return true;
                    
                case "city":
                    
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (!((data[i] >= 'A' && data[i] <= 'Z') || (data[i] >= 'a' && data[i] <= 'z') || data[i] == '\'' || data[i] == '.'
                            || data[i] == ' ' || data[i] == '-'))
                            return false;
                    }
                    return true;

                case "state":

                    if (data.Length != 2) { return false; }
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (!(data[i] >= 'A' && data[i] <= 'Z'))
                            return false;
                    }
                    return true;

                case "currency":
                    bool dec = false;

                    for (int i = 0; i < data.Length; i++)
                    {
                        if (!((data[i] >= '0' && data[i] <= '9') || data[i] == '.'))
                            return false;

                        if (data[i] == '.')
                        {
                            if (dec) { return false; }

                            dec = true;
                        }
                    }
                    return true;

                case "integer":
                    
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (!(data[i] >= '0' && data[i] <= '9'))
                            return false;
                    }
                    return true;
            }
            return false;
        }
    }
}
